package com.redhat.auth.web.account;

import java.util.ArrayList;
import java.util.List;
import java.util.Set;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import com.dayatang.domain.InstanceFactory;
import com.dayatang.querychannel.service.QueryChannelService;
import com.redhat.auth.application.AccountApplication;
import com.redhat.auth.domain.Account;
import com.redhat.auth.domain.BizSystem;
import com.redhat.auth.domain.BizSystemBinding;
import com.redhat.redwork.widget.grid.AbstractGridModel;
import com.redhat.redwork.widget.grid.Order;

@Component
/**
 * lingen.liu 通过accountId,查询出所有的BizSystemBinding
 */
public class SystemAccountGridModel extends AbstractGridModel<BizSystemBinding, Account> {

	private long count;
	@Autowired
	private AccountApplication accountApplication;
	
	@Override
	public Account getCriteriaObject() {
		return new Account();
	}

	@Override
	public List<BizSystemBinding> list(Account search, int page, int pageSize, Order order) {
		List<BizSystemBinding> systems = new ArrayList();
		if(search==null) return systems;
		else{
			long id = search.getId();
			Account account = accountApplication.getAccount(id);
			Set<BizSystemBinding> bizSystemBindings = account.getBizSystemBindings();
			systems = new ArrayList(bizSystemBindings);
		}
     	setCount(systems.size());
		return systems;
	}

	@Override
	public Long count(Account search) {
		return count;
	}

	public long getCount() {
		return count;
	}

	public void setCount(long count) {
		this.count = count;
	}

	public AccountApplication getAccountApplication() {
		return accountApplication;
	}

	public void setAccountApplication(AccountApplication accountApplication) {
		this.accountApplication = accountApplication;
	}
	
	

	
	
}
